// 命名规范

// https://typescript-eslint.io/rules/
module.exports = {
    plugins: [
        "@typescript-eslint",
    ],
    rules: {
        // TS中的重载需要放在一起
        "@typescript-eslint/adjacent-overload-signatures": "error",
        // 数组表示用：[]。而非Array<>
        "@typescript-eslint/array-type": ["warn", { "default": "array" }],
        // 禁止使用的类型。类似保留关键字
        "@typescript-eslint/ban-types": ["error",
            {
                "types": {
                    "Object": { "message": "Avoid using the `Object` type. Did you mean `object`?" },
                    "Function": { "message": "Avoid using the `Function` type. Prefer a specific function type, like `() => void`." },
                    "Boolean": { "message": "Avoid using the `Boolean` type. Did you mean `boolean`?" },
                    "Number": { "message": "Avoid using the `Number` type. Did you mean `number`?" },
                    "String": { "message": "Avoid using the `String` type. Did you mean `string`?" },
                    "Symbol": { "message": "Avoid using the `Symbol` type. Did you mean `symbol`?" }
                }
            }
        ],
        // 强制实施一致的断言类型的使用.设计TS中的as
        "@typescript-eslint/consistent-type-assertions": "warn",
        // 尽量使用interface，而非type
        "@typescript-eslint/consistent-type-definitions": "warn",
        // 需要一致的成员声明顺序
        "@typescript-eslint/member-ordering": "warn",
        // 命名约定
        "@typescript-eslint/naming-convention": [
            "warn",
            {
                "selector": ["default"],
                "format": ["camelCase", "PascalCase"],
                "leadingUnderscore": "forbid",
                "trailingUnderscore": "allow"
            },
            {
                "selector": ["variable"],
                "modifiers": ["global", "const"],
                "format": ["UPPER_CASE", "camelCase", "PascalCase"]
            },
            {
                "selector": ["function"],
                "format": ["camelCase", "PascalCase"]
            },
            {
                "selector": ["parameter"],
                "format": ["camelCase"]
            },
            {
                "selector": ["typeAlias"],
                "format": ["PascalCase"]
            },
            {
              "selector": ["interface"],
              "format": ["PascalCase"]
            },
            {
                "selector": ["enumMember"],
                "format": ["PascalCase"]
            },
            {
                "selector": ["method"],
                "filter": "^toJSON$",
                "format": null,
                "trailingUnderscore": "allow"
            }
        ],
        // number string 和 boolean类型禁止显示声明
        "@typescript-eslint/no-inferrable-types": ["warn", { "ignoreParameters": true }],
        "no-shadow": "off",
        // 禁止变量声明与外层作用域的变量同名
        "@typescript-eslint/no-shadow": ["error", { "hoist": "all" }],
        // Enforces that type arguments will not be used if not required.
        "@typescript-eslint/no-unnecessary-type-arguments": "warn",
        // 不必要的类型声明
        "@typescript-eslint/no-unnecessary-type-assertion": "warn",
        // 先定义，后使用
        "@typescript-eslint/no-use-before-define": "error",
        // 定义function类型的约束
        "@typescript-eslint/prefer-function-type": "warn",
        // 重载的一些写法
        "@typescript-eslint/unified-signatures": "error",
        // 构造函数中 super() 的调用
        "constructor-super": "error",
        // 强制或禁止调用无参构造函数时有圆括号
        "new-parens": "error",
        // 禁止出现重复的 case 标签
        "no-duplicate-case": "error",
        // 禁止对 String，Number 和 Boolean 使用 new 操作符
        "no-new-wrappers": "error",
        // 禁止多次声明同一变量
        "no-redeclare": "error",
        // 禁用稀疏数组 [,]
        "no-sparse-arrays": "error",
        // 不允许初始化变量值为 undefined
        "no-undef-init": "error",
        // 禁用var
        "no-var": "error",
        // 对象字面量简写语法 var x = "str"; var obj = { x }
        "object-shorthand": "error",
        // 强制函数中的变量要么一起声明要么分开声明
        "one-var": ["error", "never"],
        // 要求使用 const 声明那些声明后不再被修改的变量
        "prefer-const": "error",
        // 要求对象字面量属性名称用引号括起来。如：{"a": 23}，这的a就不需要括起来
        "quote-props": ["error", "as-needed"],
    }
}